package cn.colat.micse.common.code;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ResCode {
    REQUEST_SUCCESS(200, "Request_Success", "请求成功"),
    REQUEST_ERROR(4000, "Request_Error", "请求失败"),

    NO_LOGIN(40001, "No_Login", "未登录"),
    NO_ROLE(40002, "No_Role", "您不是[%s]角色"),
    NO_PERMISSION(40003, "No_Permission", "您没有[%s]权限"),
    MISSING_PARAMETER(40004, "Missing_Parameter", "缺少必要参数"),
    ARGUMENT_TYPE_MISMATCH(40005, "Argument_Type_Mismatch", "参数类型不匹配"),
    HTTP_METHOD_NOT_SUPPORTED(40006, "Http_Method_Not_Supported", "不支持[%s]请求，请使用%s请求"),
    ILLEGAL_ARGUMENTS(40007, "Illegal_Arguments", "参数错误"),
    PARAMETER_VIOLATION_ERROR(40007, "Parameter_Violation_Error", "参数校验不通过：%s"),


    ILLEGAL_ACCESS(40030, "Illegal_Access", "非法访问"),
    TO_MANY_REQUEST(40031, "To_Many_Request", "请求太过频繁"),

    SERVER_ERROR(5000, "Server_Error", "太忙啦~，休息会儿吧~");
    // ==========  业务异常从6000开始  ==========

    private final Integer code;
    private final String codeText;
    private String message;

    /**
     * 格式化输出消息
     */
    public ResCode format(Object... arg) {
        this.message = String.format(this.message, arg);
        return this;
    }
}
